<?php
$url = $params["url"]["url"];
if (strpos($url, '/') !== 0) {
    $url = '/'.$url;
}

if (! isset($field) || ! isset($obj)) {
    throw new Exception();
}

if (! isset($caption)) {
    if (! isset($msg)) {
        $msg = $field;
    }
    if (! isset($domain)) {
        $domain = null;
    }
    $caption = __d($domain, $msg, true);
}

if (array_key_exists($field, $obj->orderFields)) {

    $field = new Sort($field);

    $new_url = $obj->urlFor($url, $field);

    $attributes = array();
    $attributes['onclick'] = $obj->onclickFor($new_url, $field);
    if (! $obj->is_primary($field)) {
       // $attributes['class'] = 'not-sorted';
    }

    ?><table class="sys_layout"><?php
    ?><tr class="sys_clear"><?php
    ?><td class="sys_clear"><?php
        ?><?=$html->link($caption, $new_url, $attributes);?><?php
    ?></td><?php
    ?><td class="sys_clear sort-label-container"><span class="sort-label-wrapper"><?php
        if ($obj->is_primary($field)) {
            ?><span class="sort-label"><?php
                if ($obj->directFor($field) == Sort::DESC) {
                    ?>&#9650;<?php
                } else {
                    ?>&#9660;<?php
                }
            ?></span><?php
        }
    ?></span></td><?php
    ?></tr><?php
    ?></table><?php

} else {
    ?><?=$caption;?><?php
}
?>